package cn.catsdad.base.controller;

import cn.catsdad.base.web.GlobalExceptionHandler;
import cn.catsdad.util.DateUtil;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.beans.PropertyEditorSupport;
import java.util.Date;

/**
 * 框架controller,提供全局异常处理和数据转换
 *
 * @author xuyl
 * @version 1.0 2024/7/14
 */
public abstract class FrameController extends GlobalExceptionHandler {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        // Date 类型转换
        binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
            @Override
            public void setAsText(String text) {
                setValue(DateUtil.genericParse(text));
            }
        });
    }

}
